﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Zad8
{
    public static class Extensions
    {
        public static string CapitalizeFirstLetterOfEachWord(this string str)
        {
            char[] separators = {' ', ','};
            string[] splittedStr = str.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < splittedStr.Length; i++)
            {
                string word = splittedStr[i];
                splittedStr[i] = word[0].ToString().ToUpper() + word.Substring(1);
            }
            string result = null;
            foreach (var item in splittedStr)
        	{
        		 result = result + item + " ";
        	}
            return result;
        }

        public static string CapitalizeTitles(this string str)
        {
            str = str[0].ToString().ToUpper() + str.Substring(1);
            StringBuilder result = new StringBuilder(str);
            for (int i = 0; i < str.Length; i++)
            {
                if (i == str.Length - 1)
                {
                    break;
                }
                if (char.IsDigit(str[i]) || char.IsLetter(str[i]))
                {
                    continue;
                }
                else
                {
                    result[i + 1] = Convert.ToChar(result[i + 1].ToString().ToUpper());
                }
            }
            return result.ToString();
        }

    }
    class Program
    {
        static void Main()
        {
            string str = "%kjahsda jhdasd hgdsasd, wdwwddwd,dwdwd Klihf-dadwd";
            Console.WriteLine(str.CapitalizeTitles());
            Console.WriteLine();
            Console.WriteLine(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(str));

        }
    }
}
